package com.lang.downloader.http.Interceptor;

import com.lang.downloader.http.header.HttpResponseHeader;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import org.jetbrains.annotations.NotNull;

import java.io.IOException;

/**
 * 配置响应头
 */
public class HttpResponseHeaderInterceptor implements Interceptor {
    private final HttpResponseHeader responseHeader;

    public HttpResponseHeaderInterceptor(HttpResponseHeader responseHeader) {
        this.responseHeader = responseHeader;
    }

    @NotNull
    @Override
    public Response intercept(@NotNull Chain chain) throws IOException {
        Request request = chain.request();
        Response response = chain.proceed(request);
        responseHeader.headers(response.headers());
        return response;
    }
}
